package com.example.administrator.demo_news;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

public class syFragment extends Fragment {
    private final String[] mTitles = {
            "热门", "iOS"
    };
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private MyPagerAdapter myPagerAdapter;
    @Override
    public void onCreate ( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    public View onCreateView( LayoutInflater inflater,  ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.sylayout,null);
        mFragments.add(new kjFragment());
        mFragments.add(new ylFragment());
        ViewPager vp=view.findViewById(R.id.vp);
        myPagerAdapter =new MyPagerAdapter(getChildFragmentManager());
        vp.setAdapter(myPagerAdapter);
        SlidingTabLayout slidingTabLayout=view.findViewById(R.id.tl);
        slidingTabLayout.setViewPager(vp);
        return view;
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
